#ifndef __WATCH_H__
  #define __WATCH_H__

#include <string>
#include <iostream>
#include <cstdio>
#include <ctime>

using namespace std;

//! An implementation for stopwatch

/*!
A simple implementation for stopwatch.

Implementation date: 2006

Usage:

\code
watch w1;
w1.start();
...
w1.stop();
cout << w1 << endl;
\endcode
*/

class watch {

friend ostream &operator<<(ostream &os, watch &w); // stops the watch

private:
  unsigned long long elapsed_time; // in milliseconds
  clock_t c;
  bool is_running;

public:
  //! starts the stopwatch
  void start();

  //! stops the stopwatch
  void stop();

  //! returns the number of elapsed millisecond(s). also calls the stop()
  unsigned long long get_elapsed_milliseconds();

  //! returns the number of elapsed second(s). also calls the stop()
  unsigned long long get_elapsed_seconds();

  //! returns the number of elapsed minute(s). also calls the stop()
  unsigned long long get_elapsed_minutes();

  //! returns the number of elapsed hours(s). also calls the stop()
  unsigned long long get_elapsed_hours();

  //! returns the number of elapsed day(s). also calls the stop()
  unsigned long long get_elapsed_days();

  //! returns the elapsed time in string format. also calls the stop()
  string &get_elapsed_time(string &output);

  //! returns the curent date and time in string format
  string &get_current_time(string &output) const;

  //! default constructor
  watch(bool auto_start = false);

  //! destructor (non-virtual: please do not inherit from this class)
  ~watch();
}; // class watch


#endif
